﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TrailMapManager.Common.Track
{
    public class TrailTrack : BaseViewLogic
    {
        #region properties
        private ObservableCollection<TrailTrackPoint> _points;
        public ObservableCollection<TrailTrackPoint> Points
        {
            get
            {
                if (_points == null)
                {
                    _points = new ObservableCollection<TrailTrackPoint>();
                }
                return _points;
            }
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; NotifyPropertyChanged("Name"); }
        }

        private string _description;
        public string Description
        {
            get { return _description; }
            set { _description = value; NotifyPropertyChanged("Description"); }
        }

        private TimeSpan _duration;
        public TimeSpan Duration
        {
            get { return _duration; }
            set { _duration = value; NotifyPropertyChanged("Duration"); }
        }

        private double _distance;
        public double Distance
        {
            get { return _distance; }
            set { _distance = value; NotifyPropertyChanged("Distance"); }
        }

        public string Month
        {
            get
            {
                if (Points.Count > 0)
                {
                    return Points[0].TimeStamp.ToString("MMM");
                }
                return "";
            }
        }

        public string Day
        {
            get
            {
                if (Points.Count > 0)
                {
                    return Points[0].TimeStamp.Day.ToString();
                }
                return "";
            }
        }

        public Guid Id { get; set; }

        public void ParsePointData(byte[] data)
        {
            int count = data.Length / 32;
            for (int i = 0; i < count; i++)
            {
                Points.Add(new TrailTrackPoint(data, i * 32));
            }
        }
        #endregion
    }
}
